package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface UserMapper extends BaseMapper<User> {
    //根据查询用户名称查询用户id
    @Select("select id,username,password from t_user where username = #{username}")
    UserVO findUserByUsername(@Param("username") String username);

    //根据用户id查询用户对应的角色
    @Select("SELECT tr.keyword ,tr.id " +
            "FROM t_role tr ,t_user_role tur " +
            "WHERE tur.role_id = tr.id " +
            "AND tur.user_id = #{uId}")
    List<RoleVO> findRolesByUserId(@Param("uId") Integer uId);

    //根据角色id查询查询角色权限
    @Select("select tp.keyword " +
            "from t_permission tp ,t_role_permission trp " +
            "where trp.permission_id = tp.id " +
            "and trp.role_id = #{rid}")
    List<Permission> findPermissionByRoleId(@Param("rid") Integer rid);
}
